# Maintainer: Andreas 'Segaja' Schleifer <segaja at archlinux dot org>

_gemname='globalid'
pkgname="ruby-${_gemname}"
pkgver=1.0.0
pkgrel=1
pkgdesc='URIs for your models makes it easy to pass references around'
arch=('any')
url='https://github.com/rails/globalid'
license=('MIT')
options=(!emptydirs)
depends=('ruby' 'ruby-activesupport')
makedepends=('ruby-bundler' 'ruby-rake')
#checkdepends=('ruby-activemodel')
source=("${url}/archive/v${pkgver}/${pkgname}-${pkgver}.tar.gz")
sha512sums=('228c672aa2934a726677e11a90124767f302910791153b68024aa8b44921f2ed1444903ac592c46240f19c9dae25c170405ac2a21fc269c573b066d4cd34b04d')

prepare() {
  cd "${_gemname}-${pkgver}"

  # update gemspec/Gemfile to allow newer version of the dependencies
  sed --in-place --regexp-extended 's|~>|>=|g' "${_gemname}.gemspec"
  rm Gemfile.lock
}

build() {
  cd "${_gemname}-${pkgver}"

  rake build
}

# TODO: Tests are disabled for now as there is a cyclic dependency between this package and ruby-rails
#check() {
#  cd "${_gemname}-${pkgver}"
#
#  rake test
#}

package() {
  cd "${_gemname}-${pkgver}"

  local _gemdir="$(gem env gemdir)"

  gem install --ignore-dependencies --no-user-install -i "${pkgdir}/${_gemdir}" -n "${pkgdir}/usr/bin" "pkg/${_gemname}-${pkgver}.gem"

  rm "${pkgdir}/${_gemdir}/cache/${_gemname}-${pkgver}.gem"

  install -Dm 644 MIT-LICENSE "${pkgdir}/usr/share/licenses/${pkgname}/LICENSE"
  install -Dm 644 CHANGELOG.md CONTRIBUTING.md README.md --target-directory "${pkgdir}/usr/share/doc/${pkgname}"
}
